package cn.cuilan.test.it.api;

import cn.cuilan.entity.User;
import cn.cuilan.repository.UserRepository;
import cn.cuilan.test.common.CommonTest;
import cn.cuilan.utils.Results;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * UserController集成测试
 *
 * @author zhang.yan
 */
public class UserControllerIT extends CommonTest {

    /**
     * 接口URL前缀
     */
    private final static String URL_PREFX = "/user";

    @Autowired
    private UserRepository userRepository;

    @Before
    public void before() {
        User user = new User();
        user.setUserName("17700001111");
        user.setLoginPhone("17700001111");
        user.setPassword("0961FA1FFE0A5B65A7FEEDF39245B678");
        userRepository.save(user);
    }

    @Test
    public void loginIT() {
        MultiValueMap<String, String> urlParam = new LinkedMultiValueMap<>();
        urlParam.add("username", "17700001111");
        urlParam.add("password", "123456");
        assertTrue(isSuccess(testRestTemplate.postForObject(URL_PREFX + "/login", urlParam, Results.class)));
    }

}
